#ifndef COMMANDER_H
#define COMMANDER_H

#include <QObject>
#include <QThread>
#include <QByteArray>
#include <QString>
#include <QProcess>
#include <QDebug>

class Commander : public QObject
{
    Q_OBJECT
public:
    explicit Commander(QObject *parent = nullptr) : QObject(parent){}

    void execute(const QString &command,const QString &program="cmd")
    {
        QProcess proc;
        proc.start(program,QStringList() << "/c" << command);
        if(proc.waitForStarted(6000))
        {
            emit startSuccess();
            if(proc.waitForFinished())
            {
                QString stdOut=QString::fromLocal8Bit(proc.readAllStandardOutput());
                QString stdErr=QString::fromLocal8Bit(proc.readAllStandardError());
                emit readyRead(stdErr + stdOut);
            }
        }
        else
            emit startFailure();
    }

signals:
    void startSuccess();
    void startFailure();
    void readyRead(const QString &reply);
};

#endif // COMMANDER_H
